<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<?php $this->load->view('admin/header.html')?>
<script type="text/javascript" src="<?php echo base_url()?>common/js/validateForm.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>common/js/ck.js"></script>
<script type="text/javascript" src="<?php echo base_url()?>common/laydate/laydate.js"></script>
<script type="text/javascript">
    function addgoods() {
        layer.open({
            type: 2,
            title: '商品添加',
            maxmin: true,
            shadeClose: false, //开启点击遮罩关闭层
            area: ['500px', '400px'],
            offset: ['100px', ''],
            content: '<?php echo site_url('admin/goods/addgoods')?>'
        });
    }
    function editgoods(nid) {
        url = "<?php echo site_url('admin/goods/editgoods/{nid}')?>";
        url = url.replace('{nid}', nid) + "?returnurl=" + window.location.href;
        layer.open({
            type: 2,
            title: '商品修改',
            maxmin: true,
            shadeClose: false, //开启点击遮罩关闭层
            area: ['500px', '400px'],
            offset: ['100px', ''],
            content: url
        });
    }
    function editsize(nid) {
        url = "<?php echo site_url('admin/goods/editsize/{nid}')?>";
        url = url.replace('{nid}', nid);
        layer.open({
            type: 2,
            title: '商品尺码',
            maxmin: true,
            shadeClose: false, //开启点击遮罩关闭层
            area: ['600px', '400px'],
            offset: ['100px', ''],
            content: url
        });
    }

    function editcolor(nid) {
        url = "<?php echo site_url('admin/goods/editcolor/{nid}')?>";
        url = url.replace('{nid}', nid);
        layer.open({
            type: 2,
            title: '商品颜色',
            maxmin: true,
            shadeClose: false, //开启点击遮罩关闭层
            area: ['600px', '400px'],
            offset: ['100px', ''],
            content: url
        });
    }

    function editinventory(nid) {
        url = "<?php echo site_url('admin/goods/editinventory/{nid}')?>";
        url = url.replace('{nid}', nid);
        layer.open({
            type: 2,
            title: '货存管理',
            maxmin: true,
            shadeClose: false, //开启点击遮罩关闭层
            area: ['800px', '400px'],
            offset: ['100px', ''],
            content: url
        });
    }
    function Success(data) {
        $.Success(data);
    }

    function Del(did) {
        var url = "/admin/goods/del_goods/" + did + "?returnurl=<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']?>";
        layer.confirm("确定删除", function () {
            $.post(url, null, function (data) {
                var jsonData = $.parseJSON(data);
                if (jsonData.Statu == 'ok') {
                    Success(jsonData)
                }
                else {
                    Success(jsonData)
                }
            })
        }, function () {
            layer.msg('取消删除', { icon: 0 });
        })
    }
    function BatchDel() {
        layer.confirm("确定要删除？", function (index) {
            if ($("#checkboxVal").val().length <= 0) {
                layer.msg('未选择删除项，删除取消', { icon: 0 });
                return false;
            }
            var url = "/admin/goods/batchdel_goods?returnurl=<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']?>";
            $.post(url, { "items": $("#checkboxVal").val() }, function (data) {
                if (data.Statu == "ok") {
                    Success(data)
                    $("#allcheck").attr("checked", false)
                } else {
                    Success(data)
                }
            }, "json")
        }, function () {
            layer.msg('取消删除', { icon: 0 });
        })
    }

    $(function () {
        var start = {
            elem: '#start_time',
            format: 'YYYY-MM-DD',
            max: laydate.now(), //最大日期
            istime: true,
            istoday: false,
            choose: function (datas) {
                end.min = datas; //开始日选好后，重置结束日的最小日期
                end.start = datas //将结束日的初始值设定为开始日
            }
        };
        var end = {
            elem: '#end_time',
            format: 'YYYY-MM-DD',
            max: laydate.now(),
            istime: true,
            istoday: false,
            choose: function (datas) {
                start.max = datas; //结束日选好后，重置开始日的最大日期
            }
        };
        laydate(start);
        laydate(end);
    });
</script>
<div id="dcMain">
    <!-- 当前位置 -->
    <div id="urHere">
        DouPHP 管理中心
        <b>></b>
        <strong>商品管理</strong>
    </div>
    <div id="manager" class="mainBox" style="height:auto!important;height:550px;min-height:550px;">
        <h3>
            <a href="<?php echo site_url('admin/goods/addgoods')?>" class="actionBtn">添加商品</a>商品管理
        </h3>
       <div>
           <form action="<?php echo site_url('admin/goods/goodslist')?>" method="get">
              <label>商品名称</label> <input type="text" value="" name="goods_key" id="goods_key" style="border:1px solid #808080;" />
               <input type="text" name="start_time" id="start_time" size="20" class="inpMain " value="" readonly="readonly" />
               <input type="text" name="end_time" id="end_time" size="20" class="inpMain " value="" readonly="readonly" />
               <input value="查询" type="submit" />
           </form>
       </div>
        <table width="100%" border="0" cellpadding="8" cellspacing="0" class="tableBasic">
            <tr>
                <th width="50" align="center"><label for="allcheck">选择</label> <input type="checkbox" id="allcheck" name="allcheck" class="allcheck" /></th>
                <th width="30" align="center">编号</th>
                <th align="left">商品名称</th>
                <th align="left">缩略图</th>
                <th align="left">总库存</th>
                <th align="center">操作</th>
            </tr>
            <?php foreach($goodsList as $goodsItem):?>
            <tr>
                <td align="center"><input type="checkbox" name="cklist" value="<?php echo $goodsItem->goods_id;?>" /></td>
                <td align="center"><?php echo $goodsItem->goods_id;?></td>

                <td><?php echo $goodsItem->title;?></td>
                <td><img src="<?php echo $goodsItem->imgurl;?>" style="height:40px;width:35px;" /></td>
                <td><?php echo $goodsItem->inventory_count;?></td>
                <td align="center">
                    <a href="<?php echo site_url('admin/goodsimg/goodsimglist/'.$goodsItem->goods_id)?>">图片管理</a>|
                    <a href="javascript:editsize(<?php echo $goodsItem->goods_id?>)">尺码管理</a>|
                    <a href="javascript:editcolor(<?php echo $goodsItem->goods_id?>)">颜色管理</a>|
                    <a href="javascript:editinventory(<?php echo $goodsItem->goods_id?>)">库存管理</a>|
                    <a href="<?php echo site_url('admin/goods/editgoods/'.$goodsItem->goods_id)?>">编辑</a>|
                    <a href="javascript:Del(<?php echo $goodsItem->goods_id?>)">删除</a>
                </td>
            </tr>
            <?php endforeach; ?>
            <tr>
                <td colspan="10"><a href="javascript:BatchDel()">全部删除</a></td>
            </tr>
        </table>
        <input type="hidden" value="" id="checkboxVal" />
        <div class='page'>
            <?php echo $links?>
        </div>
    </div>
</div>